﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraRichEdit.Services;
using DevExpress.Office.Utils;

namespace VNPT.Utility
{
    public partial class fXMLConfig : DevExpress.XtraEditors.XtraForm
    {
        public fXMLConfig()
        {
            InitializeComponent();
            this.Shown += (a, e) =>
            {
               // richEditControl1.Views.SimpleView.AllowDisplayLineNumbers = true;
               // richEditControl1.ReplaceService<ISyntaxHighlightService>(new VBNet_SyntaxHighlightService(richEditControl1));
               //// richEditControl1.
               // Profile.Xml xml = new Profile.Xml();
               // richEditControl1.Document.Text = System.IO.File.ReadAllText(@"C:\Documents and Settings\Ms Nam\Desktop\Download\ProfileSource\Events.cs");

                //richEditControl1.ActiveViewType = DevExpress.XtraRichEdit.RichEditViewType.Draft;
                //richEditControl1.ReplaceService<ISyntaxHighlightService>(new CustomSyntaxHighlightService(richEditControl1.Document));
                //richEditControl1.LoadDocument();
                //richEditControl1.Document.Sections[0].Page.Width = Units.InchesToDocumentsF(80f);
                //richEditControl1.Document.DefaultCharacterProperties.FontName = "Courier New";
                
                if (_section!=null &&_entry!=null)
                {
                    richEditControl1.Document.Text = xml.GetValue(_section, _entry).ToString();
                }
                else
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("Không thể lấy thông tin của entry này!","Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                

            };
            this.btnHuyBo.Click += (a, e) => this.Close();
            this.btnChapNhan.Click += (a, e) => this.Save();

        }
        Profile.Xml xml = new Profile.Xml();
        private void Save()
        {
            if (_section != null && _entry != null)
            {
                xml.SetValue(_section, _entry, richEditControl1.Document.Text);
                this.Close();
            }
        }
        string _section;
        string _entry;
        public fXMLConfig(string section, string entry, string TieuDe)
            : this()
        {
            _section = section;
            _entry = entry;

        }
    }
}
